package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.StrategyTheme;
import cn.wolfcode.luowowo.article.domain.ThemeCommend;
import cn.wolfcode.luowowo.article.query.DestFilterQuery;
import cn.wolfcode.luowowo.article.service.IStrategyThemeService;
import cn.wolfcode.luowowo.article.service.IThemeCommendService;
import cn.wolfcode.luowowo.scenic.service.IScenicService;
import cn.wolfcode.luowowo.scenic.vo.DestFilterVO;
import cn.wolfcode.luowowo.search.service.IDestinationTemplateSearchService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/destFilter")
public class DestFilterController {
    @Reference
    private IThemeCommendService themeCommendService;
    @Reference
    private IStrategyThemeService strategyThemeService;
    @Reference
    private IScenicService scenicService;
    @Reference
    private IDestinationTemplateSearchService searchService;
    @RequestMapping("")
    public String destFilter(Model model, @ModelAttribute("qo") DestFilterQuery qo){
        //回显
        //详细主题的共享数据
        List<Map<String,Object>> list = new ArrayList<>();
        List<ThemeCommend> tcList = themeCommendService.list();
        for(ThemeCommend ltc:tcList){
            Map<String,Object> map = new HashMap<>();
            List<StrategyTheme> list1 = strategyThemeService.selectByBigTheme(ltc.getId());
            map.put("list",list1);
            map.put("name",ltc.getName());
            list.add(map);
        }
        model.addAttribute("lists",list);
        return "destination/destFilter";
    }
    @RequestMapping("/filterCommend")
    public String filterCommand(Model model,@ModelAttribute("qo")DestFilterQuery qo){
        List<DestFilterVO> vos = searchService.queryDestFilter(qo);
        model.addAttribute("vos",vos);
        return "/destination/filterCommend";
    }
}
